<?php

class RemoteObject
{
	function __construct()
	{
		$this->returnResult = true;
	}
	
	public function dispatch()
	{
		global $timeZone;
		
		if ($timeZone == null)
			$timeZone = "Asia/Jakarta";
		
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		
		$method = $_REQUEST["method"];
		$callId = $_REQUEST["callId"];
		
		$i = 0;
		$paramString = "";
		
		while (array_key_exists("p$i", $_REQUEST))
		{
			$paramString .= ", \$_REQUEST['p$i']";
			$i++;
		}
		
		if ($paramString != "")
			$paramString = substr($paramString, 2);
		
		$ret = "";
		
		eval("\$ret = \$this->$method($paramString);");
		
		if ($this->returnResult)
		{
			ob_clean();
			
			$retObj = array("callId" => $callId, "result" => $ret);
			echo(json_encode($retObj));
		}
	}
}

?>